<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- 
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License. 
-->
<html>
<head>
    <link type="text/css" rel="stylesheet" href="https://struts.apache.org/css/default.css">
    <style type="text/css">
        .dp-highlighter {
            width:95% !important;
        }
    </style>
    <style type="text/css">
        .footer {
            background-image:      url('https://cwiki.apache.org/confluence/images/border/border_bottom.gif');
            background-repeat:     repeat-x;
            background-position:   left top;
            padding-top:           4px;
            color:                 #666;
        }
    </style>
    <link href='https://struts.apache.org/highlighter/style/shCoreStruts.css' rel='stylesheet' type='text/css' />
    <link href='https://struts.apache.org/highlighter/style/shThemeStruts.css' rel='stylesheet' type='text/css' />
    <script src='https://struts.apache.org/highlighter/js/shCore.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushPlain.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushXml.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJava.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushJScript.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushGroovy.js' type='text/javascript'></script>
    <script src='https://struts.apache.org/highlighter/js/shBrushBash.js' type='text/javascript'></script>
    <script type="text/javascript">
        SyntaxHighlighter.defaults['toolbar'] = false;
        SyntaxHighlighter.all();
    </script>
    <script type="text/javascript" language="javascript">
        var hide = null;
        var show = null;
        var children = null;

        function init() {
            /* Search form initialization */
            var form = document.forms['search'];
            if (form != null) {
                form.elements['domains'].value = location.hostname;
                form.elements['sitesearch'].value = location.hostname;
            }

            /* Children initialization */
            hide = document.getElementById('hide');
            show = document.getElementById('show');
            children = document.all != null ?
                    document.all['children'] :
                    document.getElementById('children');
            if (children != null) {
                children.style.display = 'none';
                show.style.display = 'inline';
                hide.style.display = 'none';
            }
        }

        function showChildren() {
            children.style.display = 'block';
            show.style.display = 'none';
            hide.style.display = 'inline';
        }

        function hideChildren() {
            children.style.display = 'none';
            show.style.display = 'inline';
            hide.style.display = 'none';
        }
    </script>
    <title>Portlet Tutorial (WebWork 2.2)</title>
</head>
<body onload="init()">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
    <tr class="topBar">
        <td align="left" valign="middle" class="topBarDiv" align="left" nowrap>
            &nbsp;<a href="home.html">Home</a>&nbsp;&gt;&nbsp;<a href="tutorials.html">Tutorials</a>&nbsp;&gt;&nbsp;<a href="portlet-tutorial-webwork-22.html">Portlet Tutorial (WebWork 2.2)</a>
        </td>
        <td align="right" valign="middle" nowrap>
            <form name="search" action="https://www.google.com/search" method="get">
                <input type="hidden" name="ie" value="UTF-8" />
                <input type="hidden" name="oe" value="UTF-8" />
                <input type="hidden" name="domains" value="" />
                <input type="hidden" name="sitesearch" value="" />
                <input type="text" name="q" maxlength="255" value="" />
                <input type="submit" name="btnG" value="Google Search" />
            </form>
        </td>
    </tr>
</table>

<div id="PageContent">
    <div class="pageheader" style="padding: 6px 0px 0px 0px;">
        <!-- We'll enable this once we figure out how to access (and save) the logo resource -->
        <!--img src="/wiki/images/confluence_logo.gif" style="float: left; margin: 4px 4px 4px 10px;" border="0"-->
        <div style="margin: 0px 10px 0px 10px" class="smalltext">Apache Struts 2 Documentation</div>
        <div style="margin: 0px 10px 8px 10px"  class="pagetitle">Portlet Tutorial (WebWork 2.2)</div>

        <div class="greynavbar" align="right" style="padding: 2px 10px; margin: 0px;">
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14047">
                <img src="https://cwiki.apache.org/confluence/images/icons/notep_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Edit Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=14047">Edit Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">
                <img src="https://cwiki.apache.org/confluence/images/icons/browse_space.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Browse Space"></a>
            <a href="https://cwiki.apache.org/confluence/pages/listpages.action?key=WW">Browse Space</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14047">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_page_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add Page"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=WW&fromPageId=14047">Add Page</a>
            &nbsp;
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14047">
                <img src="https://cwiki.apache.org/confluence/images/icons/add_blogentry_16.gif"
                     height="16" width="16" border="0" align="absmiddle" title="Add News"></a>
            <a href="https://cwiki.apache.org/confluence/pages/createblogpost.action?spaceKey=WW&fromPageId=14047">Add News</a>
        </div>
    </div>

    <div class="pagecontent">
        <div class="wiki-content">
            <div id="ConfluenceContent"><div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p><strong>Check out the new updated <a shape="rect" href="struts-2-portlet-tutorial.html">Struts 2 Portlet Tutorial</a></strong></p></div></div>

<div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>The Portlet support is experimental. Feedback is appreciated!</p></div></div>

<h1 id="PortletTutorial(WebWork2.2)-Index">Index</h1>

<ol><li><a shape="rect" href="portlet-tutorial-webwork-22.html">Introduction</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">Installing Eclipse</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">Installing JBoss Portal 2.2</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">Creating the project</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">Classpath settings</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">portlet.xml</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">web.xml</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">Hello World!</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">xwork.xml</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">JBoss Portal descriptors</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">Deployment</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">Next step</a></li><li><a shape="rect" href="portlet-tutorial-webwork-22.html">Re-deployment</a></li></ol>


<h1 id="PortletTutorial(WebWork2.2)-Step-by-StepTutorial">Step-by-Step Tutorial</h1>


<h2 id="PortletTutorial(WebWork2.2)-Introductionintro">Introduction <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-intro"></span></h2>

<p>This tutorial walks you through the process of building a simple portlet application, using Eclipse, JBoss Portal 2.2 and the WebWork Portlet framework.</p>

<h2 id="PortletTutorial(WebWork2.2)-InstallingEclipseinstall_eclipse">Installing Eclipse <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-install_eclipse"></span></h2>

<p>In the tutorial, we will be using Eclipse 3.1.1 which can be downloaded from <a shape="rect" class="external-link" href="http://www.eclipse.org" rel="nofollow">http://www.eclipse.org</a></p>

<h2 id="PortletTutorial(WebWork2.2)-InstallingJBossPortal2.2install_jboss">Installing JBoss Portal 2.2 <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-install_jboss"></span></h2>

<p>JBoss Portal 2.2 can be found at <a shape="rect" class="external-link" href="http://www.jboss.com/products/jbossportal/downloads" rel="nofollow">http://www.jboss.com/products/jbossportal/downloads</a>.</p>

<h2 id="PortletTutorial(WebWork2.2)-Creatingtheprojectcreate_project">Creating the project <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-create_project"></span></h2>

<p>A Portlet application is basically packaged as a regular web application, but with an additional descriptor; portlet.xml. The first step of the tutorial is to create the project structure in eclipse. First, let's create the Java project itself using the new project wizard. We call the project 'MyPortlet'. Make sure to select the "Create separate source and output folders" radio button, and hit "next". In the next wizard step, set the output folder for the 'src' source folder to 'MyPortlet/webapp/WEB-INF/classes'. This makes sure it will be easy for us to export the application as a WAR file when we're done.</p>

<p><em>New project wizard</em></p>

<p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="portlet-tutorial-webwork-22.data/new-project-1.jpg"></span></p>

<p><em>New project wizard, cont</em></p>

<p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="portlet-tutorial-webwork-22.data/new-project-2.jpg"></span></p>

<h2 id="PortletTutorial(WebWork2.2)-Classpathsettingsclasspath">Classpath settings <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-classpath"></span></h2>

<p>Before buliding the application itself, we need to add some required jar files to the build classpath and the WEB-INF/lib folder. Firstly, create the WEB-INF/lib folder and download the WebWork 2.2.1 distribution and unzip it to your local harddrive. Locate the jar files shown in the screenshot and and put them in the newly created WEB-INF/lib folder. Select all the jar files, and right click and select "Build Path -&gt; Add to Build Path". Now your local project should look similar to the screenshot.</p>

<p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="portlet-tutorial-webwork-22.data/buildpath.jpg"></span></p>
<div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>If there are jar files here that aren't included in the webwork distribution you have downloaded, you can safely assume that they are not needed.</p></div></div>

<h2 id="PortletTutorial(WebWork2.2)-portlet.xmlportlet.xml">portlet.xml <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-portlet.xml"></span></h2>

<p>Next thing we do is create a portlet.xml file in the WEB-INF folder. In this file, write the following:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>portlet.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;portlet-app version="1.0" xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"&gt;
  &lt;portlet&gt;
    &lt;description xml:lang="EN"&gt;My very first WebWork Portlet&lt;/description&gt;
    &lt;portlet-name&gt;MyPortlet&lt;/portlet-name&gt;
    &lt;display-name xml:lang="EN"&gt;My first WebWork Portlet&lt;/display-name&gt;

    &lt;portlet-class&gt;com.opensymphony.webwork.portlet.dispatcher.Jsr168Dispatcher&lt;/portlet-class&gt;

    &lt;init-param&gt;
      &lt;!-- The view mode namespace. Maps to a namespace in the xwork config file --&gt;
      &lt;name&gt;viewNamespace&lt;/name&gt;
      &lt;value&gt;/view&lt;/value&gt;
    &lt;/init-param&gt;
    &lt;init-param&gt;
      &lt;!-- The default action to invoke in view mode --&gt;
      &lt;name&gt;defaultViewAction&lt;/name&gt;
      &lt;value&gt;index&lt;/value&gt;
    &lt;/init-param&gt;

    &lt;expiration-cache&gt;0&lt;/expiration-cache&gt;

    &lt;supports&gt;
      &lt;mime-type&gt;text/html&lt;/mime-type&gt;
    &lt;/supports&gt;

    &lt;supported-locale&gt;en&lt;/supported-locale&gt;

    &lt;portlet-info&gt;
      &lt;title&gt;My very own WebWork Portlet&lt;/title&gt;
      &lt;short-title&gt;WWPortlet&lt;/short-title&gt;
      &lt;keywords&gt;webwork,portlet&lt;/keywords&gt;
    &lt;/portlet-info&gt;
  &lt;/portlet&gt;
&lt;/portlet-app&gt;
</pre>
</div></div>
<p>This portlet.xml file sets up the portlet using the <em>com.opensymphony.webwork.portlet.dispatcher.Jsr168Dispatcher</em> Portlet implementation. It also tells the Portlet that it will map the <em>view</em> portlet mode to a <em>/view</em> namespace in the XWork configuration, which we must remember when building our XWork actions. In addition, it tells the portlet that if it does not find an action parameter in the portlet request, the default action to invoke is the "index" action, which<br clear="none">
should reside in the <em>/view</em> namespace in our xwork configuration.</p>

<h2 id="PortletTutorial(WebWork2.2)-web.xmlweb.xml">web.xml <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-web.xml"></span></h2>

<p>The WebWork Portlet support also requires you to include a web.xml descriptor that sets up some special servlets and filters needed to enable support for the WebWork tag libraries and template languages, since it relies on some of the interfaces and classes in the Servlet API. So create a web.xml file in the WEB-INF folder, and add the following:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>web.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"&gt;
&lt;web-app&gt;
	&lt;filter&gt;
		&lt;filter-name&gt;webwork&lt;/filter-name&gt;
		&lt;filter-class&gt;
			com.opensymphony.webwork.dispatcher.FilterDispatcher
		&lt;/filter-class&gt;
	&lt;/filter&gt;

	&lt;filter-mapping&gt;
		&lt;filter-name&gt;webwork&lt;/filter-name&gt;
		&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
	&lt;/filter-mapping&gt;

	&lt;listener&gt;
		&lt;listener-class&gt;
			com.opensymphony.webwork.portlet.context.ServletContextHolderListener
		&lt;/listener-class&gt;
	&lt;/listener&gt;


	&lt;servlet&gt;
		&lt;servlet-name&gt;preparator&lt;/servlet-name&gt;
		&lt;servlet-class&gt;
			com.opensymphony.webwork.portlet.context.PreparatorServlet
		&lt;/servlet-class&gt;
	&lt;/servlet&gt;

	&lt;taglib&gt;
		&lt;taglib-uri&gt;/webwork&lt;/taglib-uri&gt;
		&lt;taglib-location&gt;/WEB-INF/lib/webwork-2.2.1.jar&lt;/taglib-location&gt;
	&lt;/taglib&gt;

&lt;/web-app&gt;
</pre>
</div></div>
<p>The FilterDispatcher makes sure that URLs to stylesheets and js files within the webwork jar file resolve correctly. The ServletContextHolderListener is a Servlet context listener that stores a reference to the servlet context of the web application. This is needed by some of the initialization procedures used in the WebWork Portlet. The 'preparator' servlet is a special servlet that, before dispatching to a view (like JSP/ftl or velocity) initializes the HttpServletRequest/Response, and other Servlet API classes in the ServletActionContext that is used in many of the JSPs and templates.</p>

<h2 id="PortletTutorial(WebWork2.2)-HelloWorld!hello_world">Hello World! <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-hello_world"></span></h2>

<p>With these basic project structure, <em>portlet.xml</em> and <em>web.xml</em> in place, it's time to do the mandatory "Hello World" example, so let's create a place to store our JSP files. Create a <em>WEB-INF/pages/view</em> folder, and within this folder, create the file "helloWorld.jsp". In this file, we simply put:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>helloWorld.jsp</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;H2&gt;Hello world!&lt;/H2&gt;
</pre>
</div></div>

<h2 id="PortletTutorial(WebWork2.2)-xwork.xmlxwork.xml">xwork.xml <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-xwork.xml"></span></h2>

<p>At this point, it's time to prepare the xwork configuration file, xwork.xml. Create an empty file named xwork.xml in the root of the 'src' folder. In this file we put:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>xwork.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
&lt;!DOCTYPE xwork PUBLIC
    "-//OpenSymphony Group//XWork 1.0//EN"
    "http://www.opensymphony.com/xwork/xwork-1.0.dtd"&gt;
&lt;xwork&gt;
	&lt;include file="webwork-portlet-default.xml" /&gt;

	&lt;package name="view" extends="webwork-portlet-default"
		namespace="/view"&gt;
		&lt;action name="index"
			class="com.opensymphony.xwork.ActionSupport"&gt;
			&lt;result name="success"&gt;/WEB-INF/pages/view/helloWorld.jsp&lt;/result&gt;
		&lt;/action&gt;
	&lt;/package&gt;
&lt;/xwork&gt;
</pre>
</div></div>
<div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
<p>If you're using version 2.2.1 of WebWork, include the file webwork-default.xml instead.</p></div></div>
<p>&#160;<br clear="none">
&#160;<br clear="none">
Some important things to notice are that we create a package with namespace <em>view</em>, and our package extends the <em>webwork-portlet-default</em> package. The <em>webwork-portlet-default</em> package contains some special result types needed to run WebWork/XWork in a portlet container.</p>

<h2 id="PortletTutorial(WebWork2.2)-JBossPortaldescriptorsjboss_descriptors">JBoss Portal descriptors <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-jboss_descriptors"></span></h2>

<p>In addition to the regular <em>portlet.xml</em> and <em>web.xml</em> descriptors, JBoss Portal 2.2 requires us to add a couple of JBoss specific descriptor files. On of these descriptor files is named according to the name of the context root of our application, which in this case is the name of the exported war file itself. We will later create a war file named MyPortlet.war, so the name of the JBoss descriptor becomes 'MyPortlet-object.xml'. So we create this file in the WEB-INF folder, and insert the following text:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>MyPortlet-object.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;deployments&gt;
	&lt;deployment&gt;
		&lt;if-exists&gt;overwrite&lt;/if-exists&gt;
		&lt;parent-ref&gt;default&lt;/parent-ref&gt;
		&lt;properties /&gt;
		&lt;page&gt;
			&lt;page-name&gt;MyPortlet Tutorial&lt;/page-name&gt;
			&lt;properties /&gt;
			&lt;window&gt;
				&lt;window-name&gt;MyPortletWindow&lt;/window-name&gt;
				&lt;instance-ref&gt;MyPortletInstance&lt;/instance-ref&gt;
				&lt;region&gt;center&lt;/region&gt;
				&lt;height&gt;0&lt;/height&gt;
			&lt;/window&gt;
		&lt;/page&gt;
	&lt;/deployment&gt;
	&lt;deployment&gt;
		&lt;if-exists&gt;overwrite&lt;/if-exists&gt;
		&lt;instance&gt;
			&lt;instance-name&gt;MyPortletInstance&lt;/instance-name&gt;
			&lt;component-ref&gt;MyPortlet.MyPortlet&lt;/component-ref&gt;
		&lt;/instance&gt;
	&lt;/deployment&gt;
&lt;/deployments&gt;
</pre>
</div></div>
<p>In addition, we need two other files, <em>jboss-app.xml</em> and <em>jboss-portlet.xml</em> which looks like this:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>jboss-app.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;jboss-app&gt;
   &lt;app-name&gt;MyPortlet&lt;/app-name&gt;
&lt;/jboss-app&gt;
</pre>
</div></div>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>jboss-portlet.xml</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;portlet-app&gt;
   &lt;portlet&gt;
      &lt;portlet-name&gt;MyPortlet&lt;/portlet-name&gt;
      &lt;security&gt;
      &lt;/security&gt;
   &lt;/portlet&gt;
&lt;/portlet-app&gt;
</pre>
</div></div>

<h2 id="PortletTutorial(WebWork2.2)-Deployment">Deployment</h2>

<p>Now we have a project structure that looks like this:</p>

<p><em>Project structure</em><br clear="none">
<span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="portlet-tutorial-webwork-22.data/project-structure-hello-world-1.jpg"></span></p>

<p>Now it's time to try our incredible HelloWorld portlet. In a Windows Explorer session, we select the WEB-INF folder and zip it up and name the file 'MyPortlet.war'. Drop this war file in the server/default/deploy folder of JBoss Portal, and start the server. By default, the URL for JBoss portal is <a shape="rect" class="external-link" href="http://localhost:8080/portal" rel="nofollow">http://localhost:8080/portal</a>, so point your browser to this address, and you will get to the front page of the portal, where you should get a "MyPortlet Tutorial" menu entry, as shown in the screenshot below. When pressing this menu link, you will get to our fantastic "Hello World" page!</p>

<p><em>JBoss Portal front page</em><br clear="none">
<span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="portlet-tutorial-webwork-22.data/jboss-portal-frontpage.jpg"></span></p>

<p><em>MyPortlet portlet page</em><br clear="none">
<span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="portlet-tutorial-webwork-22.data/jboss-portal-portlet-page.jpg"></span></p>

<h2 id="PortletTutorial(WebWork2.2)-Nextstepnext">Next step <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-next"></span></h2>

<p>Next, let's do something a bit more interesting, namely create a simple form and display a result page. Let's start by creating our JSP that displays our form. Create a new file, 'helloForm.jsp' in the WEB-INF/pages/view/ folder. We will use the WebWork tag library to build the form on our page. The form itself will ask the user for a first name and last name, something like this:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>helloForm.jsp</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;%@ taglib uri="/webwork" prefix="ww" %&gt;

&lt;H2&gt;Hi there! Please enter your name&lt;/H2&gt;
&lt;ww:form action="helloWorld" method="POST"&gt;
	&lt;ww:textfield label="First name" name="firstName" value="%{firstName}"/&gt;
	&lt;ww:textfield label="Last name" name="lastName" value="%{lastName}"/&gt;
	&lt;ww:submit value="Say hello!"/&gt;
&lt;/ww:form&gt;
</pre>
</div></div>
<p>Now we're ready to code some Java, not much, but at least a little bit. We create a new package in our <em>src</em> folder, let's name it <em>com.opensymphony.webwork.portlet.tutorial</em>. In this package, create a <em>HelloWorldAction</em> class. In usual WebWork manners, this class extends the ActionSupport class from the XWork framework, and we'll add a couple of properties that maps to our form in the JSP we just created:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>HelloWorldAction.java</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
package com.opensymphony.webwork.portlet.tutorial;

import com.opensymphony.xwork.ActionSupport;

public class HelloWorldAction extends ActionSupport {
	private String firstName;
	private String lastName;
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
}
</pre>
</div></div>
<p>We also need a JSP to display the processed input. We'll just use the old helloWorld.jsp and modify it a bit. As with <em>helloForm.jsp</em>, we import the WebWork tag library, and we use the <em>ww:property</em> tags to display the input from the form:</p>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>helloWorld.jsp</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;%@ taglib prefix="ww" uri="/webwork" %&gt;

&lt;H2&gt;Hello &lt;ww:property value="firstName"/&gt; &lt;ww:property value="lastName"/&gt;&lt;/H2&gt;
&lt;p/&gt;
&lt;a xhref="&lt;ww:url action="helloWorldInput"/&gt;"&gt;Back to form&lt;/a&gt;
</pre>
</div></div>

<h2 id="PortletTutorial(WebWork2.2)-Re-deploymentredeploy">Re-deployment <span class="confluence-anchor-link" id="PortletTutorial(WebWork2.2)-redeploy"></span></h2>

<p>Now we're ready to do a re-deployment of our application, so zip up a new war and drop it in the <em>server/default/deploy</em> folder. The "MyPortlet Tutorial" page will now display:</p>

<p><em>Hello World form</em><br clear="none">
<span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="portlet-tutorial-webwork-22.data/hello-world-form-1.jpg"></span></p>

<p>Enter some data, and press the "Say hello!" button, and you will get a nice little personalized "hello" message:</p>

<p><em>Personalized Hello World</em></p>

<p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="portlet-tutorial-webwork-22.data/hello-world-result-1.jpg"></span></p>

<h2 id="PortletTutorial(WebWork2.2)-Backto">Back to <a shape="rect" href="tutorials.html">Tutorials</a></h2></div>
        </div>

        
    </div>
</div>
<div class="footer">
    Generated by CXF SiteExporter
</div>
</body>
</html>
